package org.zjt.akka


/**
  *
  * Description: akka-actor 解决更好的并发问题和分布式系统设计中出现的挑战中解脱出来。 通过消息来驱动
  *
  * @author juntao.zhang
  *         Date: 2018-06-25 下午12:02
  * @see
  */

import akka.actor.{Actor, ActorSystem, Props}

import scala.io.StdIn

class PrintMyActorRefActor extends Actor {

  override def receive: Receive = {

    case "printit" =>

      val secondRef = context.actorOf(Props.empty, "second-actor")
      println(s"Second: $secondRef")
  }



}

object ActorHierarchyExperiments extends App {


  val system = ActorSystem("testSystem")

  val firstRef = system.actorOf(Props[PrintMyActorRefActor], "first-actor")

  println(s"First: $firstRef")

  firstRef ! "printit"

  println(">>> Press ENTER to exit <<<")
  try StdIn.readLine()   // 监听控制台，执行输入流
  finally system.terminate()

}